/*******************************************************************************
 * Copyright (C) 2010 Chris Wroe
 * 
 * Modifications to the initial code base are copyright of their respective
 * authors, or their employers as appropriate.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307
 ******************************************************************************/

package uk.co.wroedevelopments.semanticworkbench.store;

import org.neo4j.api.core.EmbeddedNeo;
import org.neo4j.api.core.NeoService;
import org.neo4j.util.index.LuceneIndexService;

public class Connection {

	private static NeoService Service = null;
	private static LuceneIndexService IndexService = null;
	private static final String StoreFileString = "/Users/chriswroe/testing-neo";
	
	public static NeoService startService(String storeLocation) {
		Service = new EmbeddedNeo(storeLocation);
		IndexService = new LuceneIndexService(Service);
		return Service;
		
	}
	
	public static void stopService() {
		if (IndexService!=null) {
			IndexService.shutdown();
			IndexService=null;
		}
		if (Service!=null) {
			Service.shutdown();
			Service=null;
		}
	}
	
	
	public static NeoService getDefaultService() { 
		if (Service==null) {
			Service = new EmbeddedNeo(StoreFileString);
		}
		return Service;
	}
	
	public static NeoService getService() { 
		if (Service==null) {
			throw new RuntimeException("No Neo Service Started");
		}
		return Service;
	}
	
	public static LuceneIndexService getIndexService() {
		if (IndexService==null) {
			IndexService = new LuceneIndexService(Connection.getService());
		}
		return IndexService;
	}

	
}
